package lib

import (
	"algorithms/ds"
)

func init() {
	Probs = append(Probs, Problem{
		Num:         101,
		Discription: "判断两颗树是轴对称",
		Level:       1,
		Labels: map[string]int{
			"回溯":  1,
			"二叉树": 1,
		},
	})
}

func IsSymmetric(root *ds.TreeNode) bool {
	var compare func(*ds.TreeNode, *ds.TreeNode) bool
	compare = func(node1 *ds.TreeNode, node2 *ds.TreeNode) bool {
		if node1 == nil && node2 == nil {
			return true
		}

		if node1 == nil || node2 == nil {
			return false
		}

		return node1.Val == node2.Val && compare(node1.Left, node2.Right) && compare(node1.Right, node2.Left)
	}

	return compare(root.Left, root.Right)
}
